<template>
	<view class="page">
		<view class="body">
			<!-- <navigator open-type="switchTab" hover-class="none" url="/pages/article/article" class="iconfont close-btn icon-guanbi" >&#xe624;</navigator> -->	
			<view class="login-contain">
				<view class="banner">
					<image src="@/static/images/login_banner.png" mode="widthFix"></image>
				</view>

				<view class="login-wrap">
					<view class="login-form active">
						<!-- 手机登录 -->
						<template v-if="!isWechatLogin">						
							<view class="item">
								<view class="icon">
									<image src="@/static/images/phone_icon.png" mode="widthFix"></image>
								</view>
								<input type="number" adjust-position="false" v-model="phone" placeholder="请输入手机号" />
							</view>
							<view class="item">
								<view class="icon">
									<image src="@/static/images/pw.png" mode="widthFix" style="width: 40%;"></image>
								</view>
								<input type="password" adjust-position="false" v-model="password" placeholder="请输入登录密码" />
							</view>
							<!-- <view class="item">
								<view class="icon">
									<image src="@/static/images/phone_code.png" mode="widthFix"></image>
								</view>
								<input type="number" adjust-position="false"  placeholder="输入验证码" />
								<view v-if="true" class="get-code-btn" >{{count_time_text}}</view>
								<view v-else class="get-code-btn">{{count_time_text}}</view>
							</view> -->

							<view class="btn" @click="login">登录</view>
						</template>  
						
						<view class="agree-bar" >
							<radio color="#ff9600" :checked="isAgree" @click="setAgree"></radio>
							<view class="re-pw-text">
								<text>同意并阅读</text>
								<navigator url="/pages/authorization/authorization?type=1&url=http://www.isca.cn/privacy/"
									hover-class="none">《隐私政策》</navigator>
								<!-- <navigator url="/pages/authorization/authorization?type=3"
										hover-class="none">《用户服务协议》</navigator> -->
							</view>
						</view>
					</view>

				</view>
			</view>
			 
		</view>
		 
	</view>
</template>

<script>
	import WebSocket from '@/common/websocket.js'
	import {
		replaceStr,
		checkPhone
	} from '@/common/util.js' 
	import {
		HTTP_REQUEST_URL,WSS_SERVER_URL
	} from '@/config.js'
	export default {
		name: '',
		data() {
			return {  
				user_name: '' || uni.getStorageSync('user_name'), 
				phone: '',
				password: '',
				phone_code: '',
				phone_code_type: '4', // 0/空 密码登录   1 找回密码  2 重置密码  3 登录  4 登录/注册
				count_time_text: '获取验证码',
				isSendCode: true,
				isStop: true, 
				isWechatLogin:false, 
				isAgree: false,
				timer: null,
				userInfo: {}, 

			}
		},
		async onLoad(params) {
			 
		},
		async onShow() {},
		methods: {
 
			// 同意协议
			setAgree: function() {
				this.isAgree = !this.isAgree;
			},

			// 登录
			async login() {  
				console.log(123)
				let _this = this;	
				let token=[];
				//#ifdef APP-PLUS
				 if(plus.os.name === "iOS"){
					token=null;
				}
				//#endif
				
				if (this.phone == '') {
					uni.showToast({
						icon: "none",
						title: "请输入手机号",
						mask: true
					})
					return
				} 
				if (this.password == '') {
					uni.showToast({
						icon: "none",
						title: "请输入登录密码",
						mask: true
					})
					return
				}	
				if (!this.isAgree) {
					uni.showToast({
						icon: "none",
						title: "请先同意隐私和用户服务协议",
						mask: true
					})
					return
				}  
				
				if (this.isStop) {
					this.isStop = false;
					console.log(123123)
					uni.request({
						url: HTTP_REQUEST_URL + '/api/user/login',
						method: 'POST',
						data: {
							"mobile_number": this.phone,
							"password": this.password
						},
						dataType: 'json',
						timeout: 30000,
						header: {
							"Content-Type": "application/x-www-form-urlencoded",
							'Token': token
						}, 
						success: async (res) => {   
							console.log(123123,res)
							if (res.data.code == 200) {
								uni.setStorage({
									key:'token',
									data:res.data.token
								})  
								
								_this.$store.dispatch('getUserInfo',{id:res.data.id}) 
								
								uni.showToast({
									icon:'success',
									title:res.data.msg,
									mask:true,
									duration:500,
									success() {
										setTimeout(() => {
											uni.reLaunch({
												url:'/pages/index/index'
											})
											_this.isStop = true;
										}, 500) 
									}
								}) 
								 
							} else {
								setTimeout(() => {
									uni.showToast({ 
										icon:'none',
										mask:true,
										title:res.data.msg,
										duration:1000
									}) 
									_this.isStop = true;
								}, 800)
							} 
						},
						fail: (err) => {
							_this.isStop = true;			
						}
					})
					return  
					
				}
				
				
				 

			},     

			 


		},
		onUnload() {
			 
		},
		onHide() {
			 
		},
		computed: {

		},
		components: {

		},
	}
</script>

<style lang="less" scoped>
	.page,
	page {
		background: #0349fa; 
		height: 100%;
	} 
	.body{
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
		.login-contain{
			width: 90%;
		}
	}
	.banner {	
		width: 90%;
		margin: 0 auto 20rpx;
		image {
			width: 100%;
		}

		margin-bottom: 30rpx;
	}


	.login-wrap {
		.active {
			display: block;
		}
	}

	.login-form {
		@h: 90rpx; 
		margin: 0 auto 40rpx;
		display: none;

		.item {
			display: flex;
			width: 90%;
			margin: 0 auto 40rpx;
			height: @h;
			line-height: @h;
			background: rgba(255, 255, 255, 1);
			border: 1rpx solid #f5f5f5;
			border-radius: 10rpx;

			.icon {
				width: @h;
				height: @h;
				text-align: center;
				line-height: @h;
				flex-shrink: 0;

				image {
					width: 50%;
					vertical-align: middle;
				}
			}

			input {
				flex-grow: 2;
				height: @h;
				line-height: @h;
				font-size: 30rpx;
				color: #333;
			}

			.get-code-btn {
				width: 50%;
				margin-right: 1rem;
				color: #09f;
				font-size: 30rpx;
				text-align: right;
			}
		}

		.btn {
			width: 90%;
			margin: 0 auto 20rpx;
			text-align: center;
			height: @h;
			line-height: @h;
			background: #ff9600;
			border-radius: 10rpx;
			color: #fff;
			font-size: 34rpx;
		}
	}

	.re-pw {
		display: flex;
		height: 40rpx;
		line-height: 40rpx;

		radio {
			position: relative;
			transform: scale(0.7);
			color: #666;
		}

		.active {
			color: #666;
		}

		.re-pw-text {
			font-size: 32rpx;
			color: #666;
		}
	}

	.link-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 5% 50rpx;

		.find-pw-text {
			height: 40rpx;
			line-height: 40rpx;
			font-size: 30rpx;
			color: #666;
		}

	}
	
	.register-text{
		padding: 0 5% ;
		margin-bottom: 100rpx;
		text-align: right;
		font-size: 30rpx;
		color:#fff;
	}

	.agree-bar {
		display: flex;
		align-items: center;
		padding: 0 5% 50rpx;
		color: #fff;
		font-size: 28rpx;

		radio {
			transform: scale(.7);
			color: #ff9600
		}

		.re-pw-text {
			display: flex;
		}

		navigator {
			color: #fff;
		}
	}

	.agreerule {
		display: flex;
		text-align: center;
		justify-content: center;
		position: fixed;
		left: 0;
		width: 100%;
		bottom: 40rpx;

		.icon {
			margin-right: 10rpx;
			color: #E5E5E5;
		}

		.active {
			color: #000;
		}

		.agreerule-text {
			display: flex;
			font-size: 30rpx;
			color: #999;

			navigator {
				color: #f00;
			}
		}
	}

	.code-bar {
		display: flex;
		height: 80rpx;
		border: 1rpx solid #eee;
		border-radius: 15rpx;
		margin-bottom: 40rpx;

		input {
			width: 90%;
			height: 80rpx;
			line-height: 80rpx;
			padding: 0 10rpx;
			font-size: 30rpx;
		}

		.get-code-btn {
			flex-shrink: 0;
			width: 40%;
			line-height: 80rpx;
			text-align: center;
			font-size: 30rpx;
			color: #09f;
		}
	}

	.get-code-popup {
		.phone-text {
			margin-bottom: 30rpx;
			color: #666;
			font-size: 30rpx;
		}

		.code-comfirm-btn {
			height: 70rpx;
			line-height: 70rpx;
			margin: 0 auto;
			background: #ddd;
			border-radius: 8rpx;
			color: #999;
			text-align: center;
			font-size: 30rpx;
		}

		.active {
			background: linear-gradient(#e96b5c, #ce3c2f);
			color: #fff;
		}
	}
	
	.login-type-tab{ 
		display: flex;
		justify-content: center;
		position: fixed;
		left:0;
		bottom:20rpx;
		width: 100%;   
		font-size: 30rpx;
		color:#fff;
		.btn{
			.icon{
				width: 60rpx;
				margin: 0 auto;
				image{
					width: 100%;
				}
			}
		}
		
	}
	.wx-chat-login{
		width: 100rpx;
		height: 100rpx;
	}
</style>
